package com.choichumgming.rentcat.dto;

import com.choichumgming.rentcat.model.UmsMember;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Arrays;
import java.util.Collection;

/**
 * 会员详情封装
 */

public class MemberDetails implements UserDetails {

    private UmsMember umsMember;

    private  Collection<? extends GrantedAuthority> authorities;

    public MemberDetails(UmsMember umsMember) {
        this.umsMember = umsMember;
        this.authorities = Arrays.asList(new SimpleGrantedAuthority("TEST"));

    }
    public MemberDetails() {
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        //返回当前用户的权限
        return this.authorities;
    }

    public UmsMember getUmsMember() {
        return umsMember;
    }

    public void setUmsMember(UmsMember umsMember) {
        this.umsMember = umsMember;
    }

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    @JsonIgnore
    @Override
    public String getPassword() {
        return umsMember.getPassword();
    }

    @JsonIgnore
    @Override
    public String getUsername() {
        return umsMember.getUsername();
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }


}